//
//  UserGuideManager.m
//  etionUI
//
//  Created by WangJian on 14-2-24.
//  Copyright (c) 2014年 GuangZhouXuanWu. All rights reserved.
//

#import "UserGuideManager.h"

#define USER_GUIDE_STATUS_FILE_NAME @"userGuideStatus.plist"

static CUserGuideManager *s_userGuideMagager;

@interface CUserGuideManager()

@property (nonatomic, retain) NSMutableDictionary *status;
@property (nonatomic, retain) NSString *userGuideStatusFilePath;

@end

@implementation CUserGuideManager

+ (CUserGuideManager *)userGuideManager
{
    if (s_userGuideMagager == nil)
    {
        s_userGuideMagager = [[CUserGuideManager alloc] init];
    }
    return s_userGuideMagager;
}

+ (void)releaseUserGuideManager
{
    [s_userGuideMagager release];
}

+ (EUserGuideStatus)userGuideStatusForKey:(NSString *)key
{
    return [[CUserGuideManager userGuideManager] userGuideStatusForKey:key];
}

+ (void)setUserGuideStatus:(EUserGuideStatus)status forKey:(NSString *)key
{
    return [[CUserGuideManager userGuideManager] setUserGuideStatus:status forKey:key];
}

- (id)init
{
    if (self = [super init])
    {
        self.userGuideStatusFilePath = [[XMSFileHelper documentPath] stringByAppendingPathComponent:USER_GUIDE_STATUS_FILE_NAME];
        if ([XMSFileHelper isFileExist:self.userGuideStatusFilePath] == NO)
        {
            NSDictionary *tmpDic = [NSDictionary dictionary];
            [tmpDic writeToFile:self.userGuideStatusFilePath atomically:YES];
        }
        self.status = [NSMutableDictionary dictionaryWithContentsOfFile:self.userGuideStatusFilePath];
    }
    return self;
}

- (void)dealloc
{
    [_status release];
    [_userGuideStatusFilePath release];
    [super dealloc];
}

- (EUserGuideStatus)userGuideStatusForKey:(NSString *)key
{
    NSNumber *status = [self.status objectForKey:key];
    if (status == nil)
    {
        return EUserGuideStatusNeverDisplay;
    }
    else
    {
        return [status integerValue];
    }
}

- (void)setUserGuideStatus:(EUserGuideStatus)status forKey:(NSString *)key
{
    [self.status setObject:[NSNumber numberWithInteger:status] forKey:key];
    [self.status writeToFile:[self userGuideStatusFilePath] atomically:YES];
}

@end
